package frobagroup.utils;

import org.springframework.util.Base64Utils;

/**
 * Created by Tinsley on 2016/8/4.
 */
public class BaseUtils {

    public static String encode(String p) {
        String encode = null;
        try{
            encode = Base64Utils.encodeToString(p.getBytes("UTF-8"));
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return encode;
    }

    public static String decode(String p) {
        String decode = null;
        try{
            decode = new String(Base64Utils.decodeFromString(p),"UTF-8");
        }catch (Exception e){
            e.printStackTrace();
        }
        return decode;
    }

    public static String encodeURL(String url) {
        String encode = null;
        try{
            encode = Base64Utils.encodeToUrlSafeString(url.getBytes("UTF-8"));
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return encode;
    }

    public static String decodeURL(String url) {
        String decode = null;
        try{
            decode = new String(Base64Utils.decodeFromUrlSafeString(url),"UTF-8");
        }catch (Exception e){
            e.printStackTrace();
        }
        return decode;
    }
}
